home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Languages / Caml Light 0.7 / examples / basics / fib.ml next >
Text File  |  1995-06-01  |  443b  |  20 lines

  1. (* The Fibonacci function, once more. *)
  2.  
  3. let rec fib n =
  4.   if n < 2 then 1 else fib(n-1) + fib(n-2)
  5. ;;
  6.  
  7. if sys__interactive then () else
  8. if vect_length sys__command_line <> 2 then begin
  9.   print_string "Usage: fib <number>";
  10.   print_newline()
  11. end else begin
  12.   try
  13.     print_int(fib(int_of_string sys__command_line.(1)));
  14.     print_newline()
  15.   with Failure "int_of_string" ->
  16.     print_string "Bad integer constant";
  17.     print_newline()
  18. end
  19. ;;
  20.